// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SCHEDULE_SQR_S25 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 SCH",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.False, HL7Required.True,"SCH")]
	    public SCH SCH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 NTE",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 PATIENT",15)]
  	    [HL7Field(HL7Version.v23, 15, HL7Repeat.False, HL7Required.False,"PATIENT_SQR_S25")]
	    public PATIENT_SQR_S25 PATIENT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("27 RESOURCES",27)]
  	    [HL7Field(HL7Version.v23, 27, HL7Repeat.True, HL7Required.True,"RESOURCES_SQR_S25")]
	    public RESOURCES_SQR_S25[] RESOURCES {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("39 GENERAL_RESOURCE",39)]
  	    [HL7Field(HL7Version.v23, 39, HL7Repeat.False, HL7Required.False,"GENERAL_RESOURCE_SQR_S25")]
	    public GENERAL_RESOURCE_SQR_S25 GENERAL_RESOURCE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			SCH = PopSegmentParseAndCheckRequired<SCH>(availableData, options, "SCH");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			PATIENT = ProcessGroup<PATIENT_SQR_S25>(availableData, options, "PATIENT");
			RESOURCES = ProcessGroupArray<RESOURCES_SQR_S25>(availableData, options, "RESOURCES");
			GENERAL_RESOURCE = ProcessGroup<GENERAL_RESOURCE_SQR_S25>(availableData, options, "GENERAL_RESOURCE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isSCH = availableData.StartsWith("SCH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SCH", options.Version) || isSCH) {
				return isSCH;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			PATIENT_SQR_S25 testPATIENT_SQR_S25 = new PATIENT_SQR_S25();
			bool grpCCPATIENT_SQR_S25 = (testPATIENT_SQR_S25.CanConsume(availableData, options));
			if (IsRequired("PATIENT", options.Version) || grpCCPATIENT_SQR_S25) {
				return grpCCPATIENT_SQR_S25;
			}
			RESOURCES_SQR_S25 testRESOURCES_SQR_S25 = new RESOURCES_SQR_S25();
			bool grpCCRESOURCES_SQR_S25 = (testRESOURCES_SQR_S25.CanConsume(availableData, options));
			if (IsRequired("RESOURCES", options.Version) || grpCCRESOURCES_SQR_S25) {
				return grpCCRESOURCES_SQR_S25;
			}
			GENERAL_RESOURCE_SQR_S25 testGENERAL_RESOURCE_SQR_S25 = new GENERAL_RESOURCE_SQR_S25();
			bool grpCCGENERAL_RESOURCE_SQR_S25 = (testGENERAL_RESOURCE_SQR_S25.CanConsume(availableData, options));
			if (IsRequired("GENERAL_RESOURCE", options.Version) || grpCCGENERAL_RESOURCE_SQR_S25) {
				return grpCCGENERAL_RESOURCE_SQR_S25;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SCHEDULE";
			}
        }

        static SCHEDULE_SQR_S25() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SCHEDULE_SQR_S25));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (SCH != null) {
			string segmentValue = SCH.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PATIENT != null) {
			string segmentValue = PATIENT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RESOURCES != null && RESOURCES.Length > 0) {
			for (int i = 0; i < RESOURCES.Length; i++) {
				string segmentValue = RESOURCES[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (GENERAL_RESOURCE != null) {
			string segmentValue = GENERAL_RESOURCE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

